#ifndef DBINTERFACE_H
#define DBINTERFACE_H
#include <string>
#include "sqlite3.h"
#include "../common/RuleSet.h"


using namespace std;

typedef struct 
{
	char ruleName[15]; 
	char time[12];
	char event[100];
	char condition[20];
	char cmptype[2];
	char action[100];
	char priority[4];
	char owner[20];
}t_Rule;

class CDBInterface
{
public:
    
	CDBInterface(string dataPath)
	{
		pDB=NULL;
		m_strPath=dataPath;
	}

	int select1();
	int insert1();

	int createTable(string sqlCreatTable);
    
	int open();

	sqlite3* getpdb()
	{
		return pDB;
	}
	sqlite3 ** getppdb()
	{
		return &pDB;
	}

	int insertDataTable(string  itemName ,string  itemValue);

	void close(void)
	{
		sqlite3_close(pDB);
	}

	string GetAllRec(string tblname,string itemname= "");
	int delOneRec(string tblname,string name,string value);
	void loadAllRuleFrmDB();
	int SaveOneRule(string & rule_name,CRule & rule);

private:
	sqlite3* pDB;
	string m_strPath;
	
};

static int callback(void *NotUsed, int argc, char **argv, char **azColName);
#endif
